<script language="Javascript">

function printImage(image_id){
   var image_to_print = image_id;
   //open a new blank document to show and print the image
   //you can put whatever parameters you want in the third arguement
   var oWin = window.open("","newWin", "height=490,width=240");
   oWin.document.write('<html><head><title>' + image_id + '</title></head>');
   oWin.document.write('<body onLoad="javascript: window.print()">');
   oWin.document.write('<img src="' + image_to_print + '" /><br><br>');
   oWin.document.write('<button onclick="javascript: window.print()">Print Badge</button>');
   oWin.document.write('</body></html>');
}
</script>
<?php

//$cmd = '/home/rockedg1/bin/wkhtmltoimage --crop-h 687 --crop-w 395 --crop-x 5 --crop-y 5 http://badge.rockedge.org/print_badge_9.php /home/rockedg1/tmp/test5.png 2>&1';
$cmd = '/var/www/html/badge/cgi-bin/wkhtmltoimage --crop-h 687 --crop-w 395 --crop-x 5 --crop-y 5 http://wormgear.us.to/badge/print_badge_9.php /tmp/test5.png 2>&1';

exec($cmd, $output);

// The file

$filename = '/tmp/test5.png';
$filename_out = '/tmp/badge9_out.png';
$src = $filename_out;  // source folder or file
$dest = '/var/www/html/badge/badge9_out.png';   // destination folder or file
// Content type
//header('Content-Type: image/png');

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = 227 ;
$new_height = 400;

$image = imagecreatefrompng($filename);

$image = imagescale($image, $new_width, $new_height);
// Output
//imagepng($image, null, 0);
imagepng($image, $filename_out);
imagedestroy($image);

shell_exec("cp -r $filename_out $dest");

// header( 'Location: download.php' ) ;
?>

<div>
<input type="button" onClick="printImage('badge9_out.png')" value="  Prepare Badge Image"/>
</div> 